package com.ddtech.business.course.controller;


import com.ddtech.business.course.entity.CourseChapter;
import com.ddtech.business.course.query.ChapterQuery;
import com.ddtech.business.course.service.CourseChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 章节表 前端控制器
 * </p>
 *
 * @author bin_pu
 * @since 2023-02-06
 */
@Api(tags = "业务-章节管理")
@RestController
@RequestMapping("/course/chapter")
public class CourseChapterController {
    @Autowired
    private CourseChapterService courseChapterService;

    @ApiOperation(value = "查询章节树")
    @GetMapping(value = "/tree")
    public ResponseEntity getTree(ChapterQuery chapterQuery) {
        return new ResponseEntity(courseChapterService.getTree(chapterQuery), HttpStatus.OK);
    }

    @ApiOperation(value = "新增章节树")
    @PostMapping(value = "/create")
    public ResponseEntity create(@RequestBody CourseChapter courseChapter) {
        courseChapterService.create(courseChapter);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation(value = "删除章节树")
    @PostMapping(value = "/del/{id}")
    public ResponseEntity del(@PathVariable String id) {
        courseChapterService.del(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
